import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.SpinnerNumberModel;
import javax.swing.border.EmptyBorder;
import javax.swing.JSpinner;
import javax.swing.JLabel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;


public class DelaySettings extends JDialog {

	private final JPanel contentPanel = new JPanel();

	/**
	 * Create the dialog.
	 */
	public DelaySettings(final Test test) {
		setResizable(false);
		setBounds(100, 100, 360, 134);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		
		final JSpinner spinner = new JSpinner(new SpinnerNumberModel(test.getComparisonDelay(), 0, 100, 0.1));
		spinner.setBounds(292, 13, 45, 20);
		contentPanel.add(spinner);
		
		JLabel lblDelayBetweenSample = new JLabel("Delay Between Sample and Comparisons:");
		lblDelayBetweenSample.setBounds(10, 11, 258, 25);
		contentPanel.add(lblDelayBetweenSample);
		
		JLabel lblDelayAfterAnswering = new JLabel("Delay After Answering:");
		lblDelayAfterAnswering.setBounds(10, 36, 177, 20);
		contentPanel.add(lblDelayAfterAnswering);
		
		final JSpinner spinner_1 = new JSpinner(new SpinnerNumberModel(test.getAnswerDelay(), 0, 100, 0.1));
		spinner_1.setBounds(292, 36, 45, 20);
		contentPanel.add(spinner_1);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent arg0) {
						test.setComparisonDelay(((SpinnerNumberModel)(spinner.getModel())).getNumber().intValue());
						test.setAnswerDelay(((SpinnerNumberModel)(spinner_1.getModel())).getNumber().intValue());
					    dispose();
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent arg0) {
						dispose();
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setVisible(true);
	}
}
